/**
 * 股票关注相关API接口
 */

import { apiClient } from './http-client'
import { ApiResponse, API_ENDPOINTS } from '../types/api'

/**
 * 添加关注股票
 * @param stockCode 股票代码
 * @returns Promise<ApiResponse<any>>
 */
export const addToWatchlist = async (stockCode: string): Promise<ApiResponse<any>> => {
  return await apiClient.post<any>(
    API_ENDPOINTS.WATCHLIST,
    { stock_code: stockCode }
  )
}

/**
 * 取消关注股票
 * @param stockCode 股票代码
 * @returns Promise<ApiResponse<any>>
 */
export const removeFromWatchlist = async (stockCode: string): Promise<ApiResponse<any>> => {
  return await apiClient.delete<any>(
    `${API_ENDPOINTS.WATCHLIST}${stockCode}`
  )
}

/**
 * 获取用户关注的股票列表
 * @returns Promise<ApiResponse<any[]>>
 */
export const getWatchedStocks = async (): Promise<ApiResponse<any[]>> => {
  return await apiClient.get<any[]>(
    API_ENDPOINTS.WATCHLIST
  )
}

/**
 * 检查股票是否在关注列表中
 * @param stockCode 股票代码
 * @returns Promise<ApiResponse<boolean>>
 */
export const checkStockInWatchlist = async (stockCode: string): Promise<ApiResponse<boolean>> => {
  return await apiClient.get<boolean>(
    `${API_ENDPOINTS.WATCHLIST_CHECK}/${stockCode}`
  )
}

/**
 * 关注API接口对象
 */
export const watchApi = {
  addToWatchlist,
  removeFromWatchlist,
  getWatchedStocks,
  checkStockInWatchlist,
}